﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Jumpton.SFA.Server.BusinessRule.CPR;


public partial class UserControl_CPR_DATA_PAGE : System.Web.UI.UserControl
{
    private string _customerID;   //門店id

    public string CustomerID
    {
        get { return _customerID; }
        set { _customerID = value; }
    }
    private string _visitID;     //拜訪人id

    public string VisitID
    {
        get { return _visitID; }
        set { _visitID = value; }
    }
    private string _domainID;    //域id

    public string DomainID
    {
        get { return _domainID; }
        set { _domainID = value; }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //_customerID = Request.QueryString["customerID"];
            //_visitID = Request.QueryString["visitID"];
            //_domainID = Request.QueryString["domainID"];
            //_domainID = MyStateManager.DomainID.ToString();


        }
        catch (Exception)
        {
            Response.Write("参数错误");
            return;
        }


        if (!IsPostBack)
        {

            InitData();
        }
    }


    //加载数据
    private void InitData()
    {

        DataTable dt = new CPR_Form_Manager().GetCPR_FROM_Table(VisitID, DomainID, "1", "");
        DataTable dtMeasure = dt.Clone();
        foreach (DataRow row in dt.Rows)
        {
            if (dtMeasure.Select("FORM_ID='" + row["FORM_ID"].ToString() + "'").Count() < 1)
                dtMeasure.ImportRow(row);
        }
        rptMeasure.DataSource = dtMeasure;
        rptMeasure.DataBind();

    }


    protected void rptMeasure_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            GridView gv = e.Item.FindControl("gvMeasureTransation") as GridView;
            string formId = DataBinder.Eval(e.Item.DataItem, "FORM_ID").ToString();
            DataTable dt =new  CPR_Form_Manager().GetCPR_FROM_Table(VisitID, DomainID, "1", " AND c.FORM_ID=" + formId);
            gv.DataSource = dt;
            gv.DataBind();

        }

    }

    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
            return;
        DataRowView view = e.Row.DataItem as DataRowView;
        //如果是照片，则显示该照片
        if ("6" == view["INPUTTYPE"].ToString().Trim())
        {
            if ("" == view["PHOTO_ID"].ToString())
            {
                e.Row.Cells[1].Text = "无";
            }
            else
            {
                var image = new System.Web.UI.WebControls.Image();
                image.BorderStyle = BorderStyle.Solid;
                image.Height = new Unit(80, UnitType.Pixel);
                image.Width = new Unit(80, UnitType.Pixel);
                image.ImageUrl = "../IMAGE.aspx?" + view["PHOTO_ID"].ToString();
                e.Row.Cells[1].Controls.Add(image);
            }
        }
    }
}